package com.hadwinling.fileupload.client;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
import java.util.UUID;

/**
 * @author HadwinLing
 * @version V1.0
 * @Package com.hadwinling.fileupload.client
 * @date 2020/11/14 10:19
 * 文件上传服务器：多客户端上传
 * 	使用线程接受客户端
 */
public class ClientFileUpload {
    public static void main(String[] args) throws Exception {
        System.out.println("请输入您要上传的图片路径");
        Scanner scanner=new Scanner(System.in);
        String pathName=scanner.nextLine();
        Socket client=new Socket("localhost", 7777);
        //输入流，读取本地文件
        BufferedInputStream bis=new BufferedInputStream(new FileInputStream(pathName));
        //输出流，写到服务器
        BufferedOutputStream bos=new BufferedOutputStream(client.getOutputStream());
        byte[] b=new byte[3*1024];
        int len=-1;
        while((len=bis.read(b))!=-1) {
            bos.write(b, 0, len);
        }
        System.out.println("文件发送完毕");
        //关闭资源
        bos.close();
        bis.close();
        client.close();
        scanner.close();
        System.out.println("文件上传 成功");
    }
}

